package com.xiaocikuai.smallchunks.service.Transaction.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xiaocikuai.smallchunks.entity.Transaction.MaleList;
import com.xiaocikuai.smallchunks.mapper.Transaction.MaleListMapper;
import com.xiaocikuai.smallchunks.service.Transaction.IMaleListService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaocikuai.smallchunks.service.Transaction.TransactionServices;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 商品信息 服务实现类
 * </p>
 *
 * @author author1
 * @since 2024-07-13
 */
@Service
public class MaleListServiceImpl extends ServiceImpl<MaleListMapper, MaleList> implements IMaleListService {

    @Autowired
    private MaleListMapper maleListMapper;

    @Autowired
    private TransactionServices transactionServices;



    public List<MaleList> getMaleLists(int tag){
        if (tag != 0){
            LambdaQueryWrapper<MaleList> lambdaQueryWrapper = new LambdaQueryWrapper<>();
            lambdaQueryWrapper.eq(MaleList::getTag, tag);
            List<MaleList> maleLists = maleListMapper.selectList(lambdaQueryWrapper);
            for (MaleList male : maleLists){
                male.setPrice(transactionServices.getTotalPrice(male.getTid()));
            }
            return maleLists;
        }else{
            List<MaleList> maleLists =  list();
            for (MaleList male : maleLists){
                male.setPrice(transactionServices.getTotalPrice(male.getTid()));

            }
            return maleLists;
        }


    }




    public MaleList selectMaleById(MaleList maleList){
        MaleList male = maleListMapper.selectById(maleList.getTid());
        male.setPrice(transactionServices.getTotalPrice(male.getTid()));
        return male;
    }


    //设置推荐产品










}
